package code.whmmm.util.spring.quartz.job;


import code.whmmm.util.spring.quartz.task.DayTask;
import code.whmmm.util.thread.ThreadManager;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import code.whmmm.util.spring.quartz.AbstractLoggedJobWrapper;

import java.util.ArrayList;
import java.util.List;

/**
 * <b></b>
 *
 * @author Zero
 */
@Component("default-day-job")
public class DayJob extends AbstractLoggedJobWrapper {
    private final Logger log = LoggerFactory.getLogger(this.getClass());


    @Autowired
    @Qualifier("spring-thread-manager-pool")
    private ThreadManager manager;

    @Autowired
    private DefaultJobConfig config;

    /**
     * 注入全部 分小时 任务
     */
    @Autowired(required = false)
    private List<DayTask> list;

    @Override
    public String cron() {
        return config.dayCron;
    }

    @Override
    public boolean isEnable() {
        return config.dayEnable;
    }

    @Override
    protected String getJobLogName() {
        return "default-日-定时器";
    }


    @Override
    public void doJob(JobExecutionContext context) {
        if (list == null) {
            return;
        }
        List<DayTask> l = new ArrayList<DayTask>();
        for (DayTask it : list) {
            if (it.isEnable()) {
                l.add(it);
            }
        }
        manager.submit(true, l);
    }
}
